package com.zsj.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zsj.controller.base.BaseController;
import com.zsj.domain.User;
import com.zsj.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
	
	@Autowired
    private UserService userService;
	
    // 指定清除user缓存区所有缓存数据
    @CacheEvict(value ="user", allEntries=true)
	@ResponseBody
	@RequestMapping("/list")
    public List<?> queryUserAll(HttpServletRequest request, Model model) {
        List<?> reuslt = this.userService.getUsers();
		//List<?> reuslt = this.userService.findAll(); //FIXME
        return reuslt;
    }
	
    @Cacheable(value={"user"}, key="#name")
	@ResponseBody
	@RequestMapping("list/{name}")
    public List<?> queryUserAll(@PathVariable String name) {
        List<User> reuslt = this.userService.queryUserByName(name);
        return reuslt;
    }
	

}
